header {
package com.cea.papyrus.classdiagram.parsers.antlr;

import com.cea.papyrus.classdiagram.parsers.texteditor.vsldatatypes.IContext;
}



class VSLParser extends Parser;

options {
	k = 4;
	exportVocab = VSL;
	buildAST = true;
	defaultErrorHandler = false;
}
// start point : the whole file is considered as a method Body

tokens {
	MOD;
	DOT;
	DOTDOT;
	LBRACK;
	RBRACK;
	LCURLY;
	RCURLY;
	COMMA;
	COLON;
	STAR;
	EXPONENT;
	DECIMAL_STRING;
//	REAL_STRING;
	BINARY_STRING;
	HEXADECIMAL_STRING;
	QUOTE;
	DAY;
	RPAREN;
	LPAREN;
	ASSIGN;
	IDENT;
	SHARP;
	PLUS;
	MINUS;
	LE;
	LT;
	GE;
	GT; 
	EQUAL;
	DIFF;
	DIV;

	TRUE;
	FALSE;

	NULL;
	
	STRING_TEXT;

}
	

{
	private int context = -1;
	
	/**
	 * Validation state (true = validation : does not modify the property
	 */
	private boolean isValidation = false;
	
	
	private static final boolean DEBUG = false;
	/**
	 * @return the isValidation boolean
	 */
	public boolean isValidation() {
		return isValidation;
	}

	/**
	 * @param isValidation the isValidation to set (true -> do not modify the property)
	 */
	public void setValidation(boolean isValidation) {
		this.isValidation = isValidation;
	}
	
	
	public int getContext() {
		return context;
	}
	
	public void setContext(int context) {
		this.context = context;
	}
	
	 /** debug mode */
    protected final boolean debugMode = false;  	
    	
    /**
     * Debug method (~System.out.println)
     */
    private void debug(Object debug) {
    	if(debugMode) {
    		System.out.println(debug);	
    	}	
    }
	
	 /**
     * Error method (~System.err.println)
     */
    private void error(Object debug) {
    	if(debugMode) {
    		System.err.println(debug);	
    	}	
    }
	
/*	public VSLParser(TokenStream lexer, Vector names) {
		this(lexer);
		this.names = names;
	}
	
	private Vector names;*/
}

// bh main entry point for the VSL language: NFP_Value_Specification
nfpValueSpecification
	:
	{
		context = IContext.NFP_VALUE_SPECIFICATION;
	}
	(
		literal				
	|	tuple
	)
	;


// LITERAL

literal
	:
	{
		context = IContext.LITERAL;
	}
	(
		numberLiteral
	|	stringLiteral
	|	booleanLiteral
	|	nullLiteral
	|	defaultLiteral
	|   enumerationSpecification

	)
	;

enumerationSpecification
	:
	{
		context = IContext.ENUMERATION;
	}
	(
		IDENT
	)
	;


numberLiteral
	:
	{
		context = IContext.NUMBER_LITERAL;
	}
	(
		( (PLUS | MINUS)? integerLiteral | realLiteral )
	|	unlimitedLiteral
	
	)
	;

	
integerLiteral
	:
	{
		context = IContext.INTEGER_LITERAL;
	}
	(
		(
			DECIMAL_STRING
		|	HEXADECIMAL_STRING
		|	BINARY_STRING
		)
	)
	;
	

unlimitedLiteral
	:
	{
		context = IContext.UNLIMITED_LITERAL;
	}
	(
		STAR | integerLiteral
	)
	;
	

realLiteral
	:
	{
		context = IContext.REAL_LITERAL;
	}
	(
		(
			DECIMAL_STRING DOT DECIMAL_STRING
		|	scientificReal
		)
	)
	;
	

scientificReal
	:
	{
		context = IContext.SCIENTIFIC_REAL;
	}
	(
		(DECIMAL_STRING DOT DECIMAL_STRING) EXPONENT (PLUS | MINUS)? DECIMAL_STRING
	)
	;
	
	
booleanLiteral
	:
	{
		context = IContext.BOOLEAN_LITERAL;
	}
	(
		TRUE
	|	FALSE
	)
	;



nullLiteral
	:
	{
		context = IContext.NULL_LITERAL;
	}
	(
		NULL
	)
	;
	

// string literal
stringLiteral
	:
	{
		context = IContext.STRING_LITERAL;
	}
	(
		//QUOTE (BODY_TEXT | "\'" | "\\")* QUOTE
		STRING_TEXT
	)
	;
	

// default literal	
defaultLiteral
	:
	{
		context = IContext.DEFAULT_LITERAL;
	}
	(
		"-"
	)
	;	

	

// tuple

tuple
	:
	{
		context = IContext.TUPLE;
	}
	(
		LPAREN
		tupleItem	
		(
		COMMA
		tupleItem	
		)*
		RPAREN
	)
	;

tupleItem
	:
	{
		context = IContext.TUPLEITEM;
	}
	(
		(
		id:IDENT
		ASSIGN
		)
		(literal | tuple)
	)
	;


epsilon
	:
	{
		System.out.println("EPSILON");
	}
	;


